{include file="public/tabs_head" /}
    <div class="row">
        <div class="col-sm-12">
            <div class="wrapper wrapper-content animated fadeInUp">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="m-b-md pull-right">
                                    <p>
                                        &nbsp;&nbsp;
                                    <button class="layui-btn layui-btn-small  cb_f5 tips" data-tip="刷新页面"><i class="layui-icon">ဂ</i></button>    
                                    <button class="layui-btn layui-btn-small layui-btn-danger cb_case_edit tips"  data-tip="编辑项目"><i class="layui-icon"></i></button>
                                    &nbsp;&nbsp;
                                    {if $caseinfo.type != 2 }
                                    {if $caseinfo.star >0 }
                                        <button class="layui-btn layui-btn-small  layui-btn-danger tips cb_unstar"  data-tip="取消加星"><i class="layui-icon"></i></button>
                                        &nbsp;&nbsp;
                                    {else}
                                        <button class="layui-btn layui-btn-small  layui-btn-primary tips cb_star"   data-tip="加星"><i class="layui-icon"></i></button>
                                        &nbsp;&nbsp;
                                    {/if}{/if}
                                    </p>
                                </div>
                                <div class="m-b-md">
                                    <h2> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;[{$caseinfo.no}]{$caseinfo.title}
                                        <button type="button" class="btn btn-primary m-r-sm">{$caseinfo.status}</button>
                                    </h2>
                                </div>
                            </div>
                        </div>
                        <!--
                        <div class="row">
                            <div class="col-sm-5">
                                <dl class="dl-horizontal">

                                    <dt>负责人：</dt>
                                    <dd>{$caseinfo.manage_username}</dd>
                                    <dt>团队成员：</dt>
                                    <dd>{$team_info}</dd>
                                </dl>
                            </div>
                            <div class="col-sm-7" id="cluster_info">
                                <dl class="dl-horizontal">

                                    <dt>最后更新：</dt>
                                    <dd>{$caseinfo.update_time}</dd>
                                    <dt>创建于：</dt>
                                    <dd>{$caseinfo.create_time}</dd>
                               </dl>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <dl class="dl-horizontal">
                                    <dt>项目描述</dt>
                                    <dd>
                                        {$caseinfo.description}
                                    </dd>
                                </dl>
                            </div>
                        </div>
                    -->
                        <div class="row m-t-sm">
                            <div class="col-sm-12">
                                <div class="panel blank-panel">
                                    <div class="panel-body">
                                                <h4>未完成</h4>
                                                <table class="table table-striped">
                                                    <tbody>
                                                         {volist name="itemlist" id="item"}
<!--该我执行，但还未读则加亮-->
<tr {if $item.have_read == 0}style="background-color:#FFDEAD;"{/if}>
                                                            <td style="width:20px;">
<button class="layui-btn layui-btn-small layui-btn-primary cb_item_ajax_close tips" data-tip="完成任务" data-itemid={$item.id}><i class="layui-icon">&#xe616;</i></button>
                                                            </td>
                                                            <td style="width:80%;">
<h3 class="cb_show_note" data-itemid={$item.id}>{$item.create_user.username}&nbsp;&nbsp;<i>指派给</i>&nbsp;&nbsp;
<!--属于我，重点显示-->
{if $item.exe_user.id == $Think.session.user_auth.uid }
    <span class="label label-primary">{$item.exe_user.username}</span>
{else}
    {$item.exe_user.username}
{/if}
&nbsp;&nbsp;
<span class="label label-warning">{$item.type}</span>&nbsp;&nbsp;{$item.title}
{if $item.note_count >0 }
<span class="text-muted small">-{$item.note_count}次备注</span>
{/if}
{if $item.exe_user.id == $Think.session.user_auth.uid && $item.have_read == 0}
<button type="button" class="btn btn-danger cb_item_read tips" data-itemid={$item.id}  data-tip="我已了解任务，确认"><i class="fa fa-check"></i>确认</button>
{/if}
<i class="layui-icon" style="color:#f00;"></i>
<span class="pull-right text-muted small">{$item.create_time}</span>
</h3>
<!--任务备注-->
<ul class="" id="item_note_{$item.id}"{if $item.hide >0 } style="display:none;"{/if}>
    {volist name="item.note" id="note"}
    <li>
        {if !empty($note["aid"])&& $note["aid"] >0}
        <!--文件-->
            {$note.user_info.username} 上传了文件【{$note.attach_info.filename}】--<a  href="{:url('upload/download',['id'=>$note.aid])}">下载附件</a>&nbsp;(下载{$note.attach_info.count}次)
            {if $note.attach_info.is_img  >0}
            <!--是图片-->
            <a  href="#" class="preview_pictures"  data-imgurl="/public/uploads/{$note.attach_info.pathname}">预览图片</a>
            {/if}
        {else}
        <!--说明-->
            {$note.user_info.username} 说 <code>{$note.note}</code>
        {/if}
        
        <span class="pull-right text-muted small">{$note.create_time}</span>
    </li>
    {/volist}

</ul>
<!--任务备注-->
    </td>
    <td style="width:auto;">
        <p class="small">
<button type="button" class="btn btn-success btn-xs cb_upload_file" data-itemid={$item.id}><i class="fa fa-tag"></i>附件</button>
<button type="button" class="btn btn-info btn-xs cb_add_note" data-itemid={$item.id}><i class="fa fa-pencil"></i>备注</button>
{if $item.uid == $Think.session.user_auth.uid}
<!--自己新增的任务可以取消-->
<button type="button" class="btn btn-xs cb_item_cancel" data-itemid={$item.id}>取消</button>
{/if}
            </p>
        </td>

    </tr>
                                                       
{/volist}
    </tbody>
</table>
<div class="layui-form">
  <div class="layui-form-item">
    <label class="layui-form-label">安排</label>

    <div class="layui-input-inline"  style="width:150px;">
      <select name="item_exe_uid" class="item_exe_uid">
        <!--默认选中自己-->
        {volist name="userlist" id="user"}
        {if $user.id == $Think.session.user_auth.uid }
            <option value="{$user.id}" selected="true">{$user.username}</option>
        {else}
            <option value="{$user.id}">{$user.username}</option>
        {/if}
        {/volist}
      </select>
    </div>

    <div class="layui-input-inline" style="width:100px;">
      <select name="item_type" class="item_type">
        <option value="0">任务</option>
        <option value="1">资料</option>
        <option value="2">设计</option>
        <option value="3">询价</option>
        <option value="4">加工</option>
        <option value="5">安装</option>
        <option value="6">外购</option>
        <option value="7">审核</option>
        <option value="8">报价</option>
        <option value="9">合同</option>
        <option value="10">付款</option>
        <option value="11">开票</option>
        <option value="12">发货</option>
      </select>
    </div>
    <div class="layui-input-inline"style="width:300px;">
        <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入任务标题" class="layui-input" >
        <input type="text" name="case_id" style="display:none" value="{$caseinfo.id}">
    </div>
    <div class="layui-input-inline">
    <button class="layui-btn cb_add_new_item" lay-submit="" lay-filter="">提交</button>
    </div>
  </div>
</div>
                                    </div>


<!---->

<div class="panel-body">
    <h4>已完成</h4>
            
 <table class="table table-striped">
<tbody>
{volist name="enditemlist" id="item"}
<tr >
 <td style="width:20px;">
{if $item.cancel ==  1}
<!--取消的特别显示-->
<button class="layui-btn layui-btn-danger layui-btn-small cb_item_ajax_open tips" data-tip="已取消任务，点击恢复" data-itemid={$item.id}><i class="layui-icon">&#xe616;</i></button>
{else}
<button class="layui-btn layui-btn-small cb_item_ajax_open tips"  data-tip="已完成任务，点击恢复"data-itemid={$item.id}><i class="layui-icon">&#xe616;</i></button>
{/if}

</td>
<td style="width:80%;">
<h3 class="cb_show_note" data-itemid={$item.id}>{$item.create_user.username}&nbsp;&nbsp;<i>指派给</i>&nbsp;&nbsp;
<!--属于我，重点显示-->
{if $item.exe_user.id == $Think.session.user_auth.uid }
    <span class="label label-primary">{$item.exe_user.username}</span>
{else}
    {$item.exe_user.username}
{/if}
&nbsp;&nbsp;
<span class="label label-warning">{$item.type}</span>&nbsp;&nbsp;{$item.title}
{if $item.note_count >0 }
<span class="text-muted small">-{$item.note_count}次备注</span>
{/if}
<span class="pull-right text-muted small">{$item.create_time}开始-{$item.end_time}结束</span>
</h3>
<!--任务备注-->
<ul class=""id="item_note_{$item.id}"{if $item.hide >0 } style="display:none;"{/if}>
    {volist name="item.note" id="note"}
    <li>
        {if !empty($note["aid"])&& $note["aid"] >0}
        <!--文件-->
            {$note.user_info.username} 上传了文件【{$note.attach_info.filename}】--<a  href="{:url('upload/download',['id'=>$note.aid])}">下载附件</a>&nbsp;(下载{$note.attach_info.count}次)
        {else}
        <!--说明-->
            {$note.user_info.username} 说 <code>{$note.note}</code>
        {/if}
        
        <span class="pull-right text-muted small">{$note.create_time}</span>
    </li>
    {/volist}

</ul>
<!--任务备注-->
    </td>
    <td style="width:auto;">
        <p class="small">
<button type="button" class="btn btn-success btn-xs cb_upload_file" data-itemid={$item.id}><i class="fa fa-tag"></i>附件</button>
<button type="button" class="btn btn-info btn-xs cb_add_note" data-itemid={$item.id}><i class="fa fa-pencil"></i>备注</button>
            </p>
        </td>

    </tr>
                                                       
{/volist}
    </tbody>
</table>
</div>
<!---->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<!--用于显示预览图片-->
<div id="divshow" style="border: 1px solid red;position:absolute; display:none"></div>  
    <style type="text/css">        
    .preview_pictures_img { 
        max-width: 400px;
        max-height: 300px;
        background-color:#ffffff;
    }
    </style>

<!--JS-->

<script>
var upfile_item_id;
function F5() {
    location.reload();
    return false;
}
//添加上传的附件ID到任务评论里
function upload_file_deal(fid) {
    var value = {
        fid: fid,
        item_id: upfile_item_id
    };
    $.post("{:url('task/add_upload_to_item')}", value,
        function(ret) {
            var status = "1" == ret.status ? "success": "error";

            if(status == "success"){
                location.reload();// alert(iID);
            }else{
                layer.msg('操作失败！');
            }
        },"json")
}
$( ".cb_case_edit" ).click(function() {
    //iframe层-父子操作
    var id = {$caseinfo.id};
    //alert(id);
    layer.open({
    type: 2,
    area: ['700px', '550px'],
    fix: false, //不固定
    title :'修改项目',
    maxmin: true,
        content: '{:url('task/case_edit')}' + "&id=" + id
    });
    return false;
});
$( ".cb_f5" ).click(function() {
    location.reload();
    return false;
});
//新增任务
$( ".cb_add_new_item" ).click(function() {
//读取输入框的值
    var value = {
        exe_uid: $(".item_exe_uid").val(),
        type: $(".item_type").val(),
        title: $("input[name='title']").val(),
        case_id: $("input[name='case_id']").val(),
    };
    var status;
    $.post("{:url('task/item_ajax_create')}", value,
        function(ret) {
            var status = "1" == ret.status ? "success": "error";
            //alert( $("textarea[name='item_miaoshu']").val());
            iid = ret.iid;
            if(status == "success"){
                layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标
                //location.reload();
                //window.setTimeout(location.reload(), 2000);
                var iID=setTimeout(function(){
                   location.reload();// alert(iID);
                },1000);
            }else{
                layer.msg('操作失败！');
            }
        },"json")
    
    return false;
});

//完成任务
$( ".cb_item_ajax_close" ).click(function() {
    var itemid = $(this).data('itemid');
    var value = {
        id: itemid
    };
    var status;
    $.post("{:url('task/item_ajax_close')}", value,
        function(ret) {
            var status = "1" == ret.status ? "success": "error";
            if(status == "success"){
                layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标
                var iID=setTimeout(function(){
                   location.reload();// alert(iID);
                },1000);
            }else{
                layer.msg('操作失败！');
            }
        },"json")
    
    return false;
});
//恢复任务
$( ".cb_item_ajax_open" ).click(function() {
    var itemid = $(this).data('itemid');
    var value = {
        id: itemid
    };
    var status;
    $.post("{:url('task/item_ajax_open')}", value,
        function(ret) {
            var status = "1" == ret.status ? "success": "error";
            if(status == "success"){
                layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标
                var iID=setTimeout(function(){
                   location.reload();// alert(iID);
                },1000);
            }else{
                layer.msg('操作失败！');
            }
        },"json")
    
    return false;
});
//取消任务
$( ".cb_item_cancel" ).click(function() {
    var itemid = $(this).data('itemid');
    var value = {
        id: itemid
    };
    var status;
    $.post("{:url('task/item_ajax_cancel')}", value,
        function(ret) {
            var status = "1" == ret.status ? "success": "error";
            if(status == "success"){
                layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标
                var iID=setTimeout(function(){
                   location.reload();// alert(iID);
                },1000);
            }else{
                layer.msg('操作失败！');
            }
        },"json")
    
    return false;
});


//上传附件
$( ".cb_upload_file" ).click(function() {
    //iframe层-父子操作
    upfile_item_id = $(this).data('itemid');
    //alert(upfile_item_id);
    layer.open({
    type: 2,
    area: ['400px', '300px'],
    fix: false, //不固定
    title :'上传文件',
    maxmin: true,
        content: '{:url('upload/uppage')}'
    });
    return false;
});
//新增备注
$( ".cb_add_note" ).click(function() {
    upfile_item_id = $(this).data('itemid');
    //默认prompt
    layer.prompt(function(val){
        //layer.msg('得到了'+val);
        
        var value = {
            item_id: upfile_item_id,
            note: val,
        };
        var status;
        $.post("{:url('task/add_note_to_item')}", value,
            function(ret) {
                var status = "1" == ret.status ? "success": "error";
                //alert( $("textarea[name='item_miaoshu']").val());
                iid = ret.iid;
                if(status == "success"){
                    layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标
                    //location.reload();
                    //window.setTimeout(location.reload(), 2000);
                    var iID=setTimeout(function(){
                    location.reload();// alert(iID);
                    },1000);
                }else{
                    layer.msg('操作失败！');
                }
            },"json")
    });
    return false;
});
//加星
$( ".cb_star" ).click(function() {
        var id = {$caseinfo.id};
        var value = {
            case_id: id,
        };
        var status;
        $.post("{:url('task/case_ajax_star')}", value,
            function(ret) {
                var status = "1" == ret.status ? "success": "error";
                if(status == "success"){
                    layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标

                    var iID=setTimeout(function(){
                    location.reload();// alert(iID);
                    },1000);
                }else{
                    layer.msg('操作失败！');
                }
            },"json")
    return false;
});
//取消加星
$( ".cb_unstar" ).click(function() {
        var id = {$caseinfo.id};
        var value = {
            case_id: id,
        };
        var status;
        $.post("{:url('task/case_ajax_unstar')}", value,
            function(ret) {
                var status = "1" == ret.status ? "success": "error";
                if(status == "success"){
                    layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标

                    var iID=setTimeout(function(){
                    location.reload();// alert(iID);
                    },1000);
                }else{
                    layer.msg('操作失败！');
                }
            },"json")
    return false;
});
//任务已读
$( ".cb_item_read" ).click(function() {
        var id = $(this).data('itemid');;
        var value = {
            id: id,
        };
        var status;
        $.post("{:url('task/item_ajax_read')}", value,
            function(ret) {
                var status = "1" == ret.status ? "success": "error";
                if(status == "success"){
                    layer.msg('操作成功！'); //2秒后自动关闭，-1代表不显示图标

                    var iID=setTimeout(function(){
                    location.reload();// alert(iID);
                    },1000);
                }else{
                    layer.msg('操作失败！');
                }
            },"json")
    return false;
});
//
//点击展开任务详情
$( ".cb_show_note" ).click(function() {
    var id = $(this).data('itemid');
    var hide;
    if($( "#item_note_"+id ).css("display") == 'none'){
        $( "#item_note_"+id ).css("display","inline");
        hide = 0;
    }else{
        $( "#item_note_"+id ).css("display","none");
        hide = 1;
    }
    //记录到服务器
    var value = {
        id: id,
        hide:hide,
    };
    $.post("{:url('task/item_note_hide')}", value,
        function(ret) {
        },"json")
    return false;
});

</script>
<script>
layui.use('form', function(){
  var form = layui.form();
//自定义验证规则
  form.verify({
    title: function(value){
      if(value.length < 2){
        return '至少也得2个字吧';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
  });

});
</script>

{include file="public/tabs_footer" /}